<template>
    <div>
        <el-dialog v-model="ViewdialogVisible" width="80%" align-center destroy-on-close draggable>
            <template #header="{ close }">
                <div class="dialog-header flex justify-between items-center">
                    <div>研究报告查看</div>
                    <el-icon class="el-icon--left cursor-pointer" @click="close">
                        <CircleCloseFilled color="#fff" />
                    </el-icon>
                </div>
            </template>
            <div class="pt-[30px] pb-[20px] bg-white">
                <div class="px-[5px]  text-right" v-if="procInsId != null">
                    <el-link type="primary" @click="checkHistoryModalVisible = true">审核记录</el-link>
                </div>
                <el-tabs v-model="activeStep" class="demo-tabs">
                    <el-tab-pane label="基本信息" :name="0">
                        <div>
                            <!-- 基本信息 -->
                            <div class="bg-white mt-[10px]">
                                <BaseHead>基本信息</BaseHead>
                                <div class="p-[10px]">
                                    <el-descriptions title="" :column="2" border label-width="140">
                                        <el-descriptions-item label-class-name="gdlable" :span="2" label="报告题目">{{
            ruleForm.name
        }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="提交单位">{{
                ruleForm.submitUnit
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="提交时间">{{
                ruleForm.submitDate
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="是否被采纳">{{
                ruleForm.isAccept == '1' ? '是' : '否'
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="采纳对象">{{
                formatacceptObject(ruleForm.acceptObject)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="所属单位">{{
                formatUnitId(ruleForm.unitId)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="学校署名">{{
                ruleForm.schoolSign == '0' ? '第一单位' : '非第一单位'
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="项目来源">{{
                formatprojectSourceId(ruleForm.projectSourceId)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="一级学科">{{
                formatsubjectId(ruleForm.subjectId)
            }}</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="总字数">{{
                ruleForm.wordNumber
            }}万字</el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="报告电子版">
                                            <div v-for="item in ruleForm.fileList" :key="item.id">{{ item.fileName
                                                }}<el-link type="primary" style="margin-left: 8px;"
                                                    @click="downloadMet(item.id)">下载</el-link>
                                            </div>
                                        </el-descriptions-item>
                                        <el-descriptions-item label-class-name="gdlable" label="备注">{{
            ruleForm.note
        }}</el-descriptions-item>
                                    </el-descriptions>
                                </div>
                            </div>
                            <!-- 完成人信息 -->
                            <div class="bg-white mt-[10px]">
                                <BaseHead>完成人信息</BaseHead>
                                <div class="p-[10px]">
                                    <el-table :data="tableData" border style="width: 100%">
                                        <el-table-column align="center" type="index" label="署名顺序" width="80" />
                                        <el-table-column align="center" prop="authorType" label="完成人类型">
                                            <template #default="scope">
                                                {{
                                                scope.row.authorType == '1' ? '教师' : scope.row.authorType == '2' ? '学生'
                                                : '校外'
                                                }}</template>
                                        </el-table-column>
                                        <el-table-column align="center" prop="authorName" label="完成人姓名">

                                        </el-table-column>
                                        <el-table-column align="center" prop="eduLevelId" label="学历">
                                            <template #default="scope">
                                                <Feedback :id="scope.row.eduLevelId" :list="xlList">
                                                </Feedback>
                                            </template>
                                        </el-table-column>
                                        <el-table-column align="center" prop="titleId" label="职称">
                                            <template #default="scope">
                                                <el-tree-select v-model="scope.row.titleId" node-key="id" :data="zcList"
                                                    :render-after-expand="false" disabled />
                                            </template>
                                        </el-table-column>
                                        <el-table-column align="center" prop="authorUnit" label="工作单位">
                                            <template #default="scope">
                                                <span v-if="scope.row.authorType == 3">{{scope.row.authorUnit }}</span>
                                                <Feedback v-else :id="scope.row.authorUnitId" :list="sydwList"
                                                    :mapping="['codeColumn', 'valueColumn']">
                                                </Feedback>
                                            </template>
                                        </el-table-column>
                                        <el-table-column align="center" prop="workRatio" label="贡献率（%）">
                                        </el-table-column>
                                    </el-table>
                                </div>
                            </div>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="依托项目" :name="1">
                        <supportProjectView :productId="ruleForm.id"></supportProjectView>
                    </el-tab-pane>
                </el-tabs>

            </div>
        </el-dialog>
    </div>
    <CheckHistoryModal v-model="checkHistoryModalVisible" :procInsId="procInsId" :checker="checker"
        :checkDate="checkDate" />
</template>
<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import supportProjectView from "@/views/achievement/components/supportProjectView.vue"
import CheckHistoryModal from "@/views/project/components/CheckHistoryModal.vue";
const ViewdialogVisible = defineModel();
const props = defineProps({
    xlList: Array,
    zcList: Array,
    zcgsdwList: Array,
    xmlyList: Array,
    cndxList: Array,
    yjxkList: Array,
    sydwList: Array,
})

const checkHistoryModalVisible = ref(false);
const procInsId = ref(null); //流程实例id
const checker = ref("");
const checkDate = ref("");

const ruleForm = reactive({
});
const tableData = reactive([
]);


const formatUnitId = (cellValue) => {
    if (props.zcgsdwList.length && cellValue) {
        return props.zcgsdwList.find(item => item.codeColumn == cellValue).valueColumn
    } else {
        return ''
    }


}

const formatacceptObject = (cellValue) => {
    console.log(cellValue, props.jdjgList)
    if (props.cndxList.length && cellValue) {
        return props.cndxList.find(item => item.code == cellValue) ? props.cndxList.find(item => item.code == cellValue).name : ''
    } else {
        return ''
    }


}

const formatprojectSourceId = (cellValue) => {
    if (props.xmlyList.length && cellValue) {
        return props.xmlyList.find(item => item.id == cellValue) ? props.xmlyList.find(item => item.id == cellValue).label : ''
    } else {
        return ''
    }


}
const formatsubjectId = (cellValue) => {
    if (props.yjxkList.length && cellValue) {
        return props.yjxkList.find(item => item.id == cellValue) ? props.yjxkList.find(item => item.id == cellValue).label : ''
    } else {
        return ''
    }


}

const formateduLevelId = (cellValue) => {
    if (props.xlList.length && cellValue) {
        return props.xlList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}
const getRuleForm = (i) => {
    if (i.authorList && i.authorList.length > 0) {
        tableData.length = 0; // 清空数组
        tableData.push(...i.authorList); // 添加新元素

    }
    for (const key in i) {
        ruleForm[key] = i[key];
    }
    procInsId.value = ruleForm.processInstanceId;
    checker.value = ruleForm.checker;
    checkDate.value = ruleForm.checkdate;
}
const activeStep = ref(0)
const { proxy } = getCurrentInstance();
const downloadMet = (i) => {
    proxy.$download.common(i)
}
defineExpose({
    getRuleForm
})
</script>
<style lang="scss">
.gdlable {
    width: 140px;
}
</style>
<style scoped lang="scss">
@import url("@/views/achievement/index.scss");

:deep(.el-select--default) {


    .el-select__wrapper.is-disabled {
        background-color: #fff;
        box-shadow: 0 0 0 0px var(--el-select-disabled-border) inset;
        color: #606266;
        cursor: not-allowed;

        .el-select__selected-item {
            color: #606266;
        }
    }

    .el-select__suffix {
        display: none;
    }
}
</style>
